import {reqGetCatlist,reqGetSongslist,reqGetCatSongslist} from '@/api/playlist'
import {GET_CATLIST,GET_SONGS_LIST,IS_TO_LOGIN} from './mutation-types'

export default{
    namespaced: true,
    state:{
        catlist:[],
        songsList:[],
        // 分类名
        cat:'',
        // 控制login框
        isToLogin:false


    },
    actions:{
      // 获取选择分类列表
       async getCatlist({commit,state}){
            const {categories,sub} =await reqGetCatlist()
            if(!state.catlist.length){
            for (let index in categories){
            //   console.log(index)
              let catItem={
                categories:categories[index],
                sub:sub.filter((item)=>item.category===index/1)
            }
            commit("GET_CATLIST",catItem)
            }
          }
        },
        // 获取歌单列表
       async getSongslist({commit},name){
            const {playlists,cat} =await reqGetSongslist(name)
            commit("GET_SONGS_LIST",{playlists,cat})
          },
        // 获取分页器歌单列表
       async getCatSongslist({commit},data){
            const {playlists,cat} =await reqGetCatSongslist(data.cat,data.offset)
            commit("GET_SONGS_LIST",{playlists,cat})
          }

    },
    mutations:{
       [GET_CATLIST](state,catItem){
            state.catlist.push(catItem)
        },
       [GET_SONGS_LIST](state,{playlists,cat}){
        //    console.log(playlists)
          state.songsList=playlists
          state.cat=cat
        },
        [IS_TO_LOGIN](state,data){
          state.isToLogin=data
        }

    },
}